import { setDeptFormatter } from '@/utils/util';
// const deptList = setDeptFormatter();
const deptList = [];
import { useUserStore } from '@/store';
const userStore = useUserStore();
console.log('userStore.qrcodeList', userStore.qrcodeList);
console.log('userStore.workShopList', userStore.workshopList);

export const getQrcodeForType = (type = 1) => {
  const res = userStore.qrcodeList.filter(
    (item) => item.status == 0 && item.labelType == type
  );
  if (res && res.length > 0) {
    return res;
  }
  return [];
};
export const baseTypeList = [
  { label: '位移传感器', value: '1' },
  { label: '温湿度传感器', value: '2' },
  { label: '烟感传感器', value: '3' },
];

//资产分类
export const zichanType = [
  { label: 'IT类设备', value: '1' },
  { label: '其他', value: '2' },
];
export const getZichanType = (id) => {
  const res = zichanType.filter((item) => item.value == id);
  if (res && res.length > 0) {
    return res[0].label;
  }
  return '';
};

const assetTypeList = [
  { label: 'A', value: '1' },
  { label: 'B', value: '2' },
  { label: 'C', value: '3' },
  { label: 'D', value: '4' },
  { label: 'E', value: '5' },
];

export const searchList = {
  labelWidth: '80px',
  isBetween: false, // false = float 布局
  position: 'left',
  formList: [
    {
      label: '资产名称',
      val: '',
      field: 'assetName',
      type: 'input',
      width: '340px',
      rightMargin: true,
    },
    {
      label: '资产状态',
      val: '',
      field: 'assetStatus',
      type: 'select',
      width: '340px',
      rightMargin: true,
      chooseList: [
        { label: '在用', value: '1' },
        { label: '非在用', value: '2' },
      ],
    },
    {
      label: '资产分类',
      val: '',
      field: 'assetType',
      type: 'select',
      width: '340px',
      rightMargin: true,
      chooseList: userStore.assetTypeList,
      chooseListField: ['deviceName', 'id'],
    },
  ],
  showSreach: true, // 是否显示搜索按钮
};
// 表格字段
export const tableList = [
  {
    label: '序号',
    index: 'index',
    minWidth: '80px',
  },
  {
    label: '资产名称',
    prop: 'assetName',
    minWidth: '100px',
  },
  {
    label: '事业部名称',
    prop: 'businessDeptName',
    minWidth: '120px',
  },
  {
    label: 'SAP资产编码',
    prop: 'sapAssetCode',
    minWidth: '150px',
  },
  {
    label: '资产编号',
    prop: 'assetNumber',
    minWidth: '120px',
  },
  //   {
  //     label: '资产标签',
  //     prop: 'label',
  //     minWidth: '100px',
  //   },
  {
    label: '原资产编码',
    prop: 'originalAssetCode',
    minWidth: '120px',
  },

  {
    label: '规格型号',
    prop: 'specificationModel',
    minWidth: '120px',
  },

  {
    label: '资产分类',
    prop: 'assetCategory',
    minWidth: '100px',
  },
  {
    label: '资产细分类',
    prop: 'assetSubcategoryName',
    minWidth: '120px',
  },
  {
    label: '生产厂家',
    prop: 'factoryNumber',
    minWidth: '100px',
  },
  {
    label: '出厂编号',
    prop: 'manufacturingNumber',
    minWidth: '140px',
  },
  {
    label: '出厂日期',
    prop: 'productionDate',
    minWidth: '140px',
  },
  {
    label: '启用日期',
    prop: 'commissioningDate',
    minWidth: '100px',
  },
  {
    label: '原值（总价值）',
    prop: 'originalValue',
    minWidth: '120px',
  },
  //   {
  //     label: '原值（其中费用）',
  //     prop: 'originalCost',
  //     minWidth: '120px',
  //   },
  {
    label: '净值',
    prop: 'netValue',
    minWidth: '100px',
  },
  {
    label: '累计折旧',
    prop: 'accumulatedDepreciation',
    minWidth: '120px',
  },
  {
    label: '使用年限',
    prop: 'serviceLife',
    minWidth: '100px',
  },
  {
    label: '使用月份',
    prop: 'usageMonths',
    minWidth: '100px',
  },
  {
    label: '成本中心',
    prop: 'costCenter',
    minWidth: '120px',
  },
  {
    label: '保管部门',
    prop: 'custodianDepartment',
    minWidth: '120px',
  },
  {
    label: '保管人',
    prop: 'custodian',
    minWidth: '80px',
  },
  {
    label: '存放厂区',
    prop: 'fromLocation',
    minWidth: '100px',
  },

  {
    label: '存放地点',
    prop: 'storageLocation',
    minWidth: '120px',
  },
  {
    label: '使用性质',
    prop: 'usageNature',
    minWidth: '100px',
    formatter(row) {
      return row.usageNature == '1' ? '生产用' : '非生产用';
    },
  },
  {
    label: '资产状态',
    prop: 'assetStatus',
    minWidth: '100px',
    formatter(row) {
      return row.assetStatus == '1' ? '在用' : '非在用';
    },
  },
  {
    label: '类别',
    prop: 'assetType',
    minWidth: '80px',
    formatter(row) {
      const res = assetTypeList.filter((item) => item.value == row.assetType);
      if (res && res.length > 0) {
        return res[0].label;
      }
      return row.assetType;
    },
  },
  {
    label: '重量（吨）',
    prop: 'weight',
    minWidth: '100px',
  },
  {
    label: '附属电机台数',
    prop: 'affiliate_motor_count',
    minWidth: '120px',
  },
  {
    label: '附属电机总功率',
    prop: 'totalMotorPower',
    minWidth: '140px',
  },
  {
    label: '备注',
    prop: 'remarks',
    minWidth: '150px',
  },
  {
    slot: 'operation',
    width: '170',
    label: '操作',
    prop: 'options',
    notooltip: true,
    fixed: 'right',
  },
];
const baseWidth = '48%';
// 资产详情字段
export const assetsDetail = [
  {
    label: '事业部名称',
    val: '',
    field: 'businessDeptNo',
    type: 'treeSelect',
    width: baseWidth,
    require: true,
    chooseList: deptList,
    props: { label: 'deptName', value: 'deptNo', children: 'children' },
  },
  {
    label: '二维码标签',
    val: '',
    field: 'qrCode',
    type: 'select',
    width: baseWidth,
    require: true,

    chooseList: getQrcodeForType(1),
    chooseListField: ['labelCode', 'id'],
  },
  {
    label: 'SAP资产编码',
    val: '',
    field: 'sapAssetCode',
    type: 'input',
    width: baseWidth,
    require: true,
  },
  {
    label: '资产编号',
    val: '',
    field: 'assetNumber',
    type: 'input',
    width: baseWidth,
    require: true,
  },
  {
    label: '原资产编码',
    val: '',
    field: 'originalAssetCode',
    type: 'input',
    width: baseWidth,
    require: true,
  },
  {
    label: '资产名称',
    val: '',
    field: 'assetName',
    type: 'input',
    width: baseWidth,
    require: true,
  },
  {
    label: '规格型号',
    val: '',
    field: 'specificationModel',
    type: 'input',
    width: baseWidth,
    require: true,
  },
  {
    label: '资产分类',
    val: '1',
    field: 'assetCategory',
    type: 'select',
    width: baseWidth,
    require: true,

    chooseList: zichanType,
  },
  {
    label: '资产细分类',
    val: '',
    field: 'assetSubcategory',
    type: 'select',
    width: baseWidth,
    // require: true,

    chooseList: userStore.assetTypeList,
    chooseListField: ['deviceName', 'id'],
  },

  {
    label: '类别',
    val: '',
    field: 'assetType',
    type: 'select',
    width: baseWidth,
    require: true,
    chooseList: assetTypeList,
  },

  {
    label: '生产厂家',
    val: '',
    field: 'factoryNumber',
    type: 'select',
    width: baseWidth,
    require: true,

    chooseList: [{ label: '北京小米', value: '1' }],
  },
  {
    label: '出厂编号',
    val: '',
    field: 'manufacturingNumber',
    type: 'input',
    width: baseWidth,
    // require: true,
  },
  {
    label: '出厂日期',
    val: '',
    field: 'productionDate',
    type: 'date',
    width: baseWidth,
    require: true,
    check_type: 8,
  },
  {
    label: '启用日期',
    val: '',
    field: 'commissioningDate',
    type: 'date',
    width: baseWidth,
    require: true,
    check_type: 8,
  },
  {
    label: '原值（总价值）',
    val: '',
    field: 'originalValue',
    type: 'input',
    isNumber: true,
    width: baseWidth,
    require: true,
  },
  //   {
  //     label: '原值（其中费用）',
  //     val: '',
  //     field: 'originalCost',
  //     type: 'input',
  //     isNumber: true,
  //    width:baseWidth,
  //     require: true,
  //
  //   },
  {
    label: '净值',
    val: '',
    field: 'netValue',
    type: 'input',
    isNumber: true,
    width: baseWidth,
    require: true,
  },
  {
    label: '累计折旧',
    val: '',
    field: 'accumulatedDepreciation',
    type: 'input',
    isNumber: true,
    width: baseWidth,
    require: true,
  },
  {
    label: '使用年限',
    val: '',
    field: 'serviceLife',
    type: 'input',
    isNumber: true,
    width: baseWidth,
    require: true,
  },
  {
    label: '使用月份',
    val: '',
    field: 'usageMonths',
    type: 'select',
    width: baseWidth,
    require: true,

    chooseList: [
      { label: '1月', value: '1' },
      { label: '2月', value: '2' },
      { label: '3月', value: '3' },
      { label: '4月', value: '4' },
      { label: '5月', value: '5' },
      { label: '6月', value: '6' },
      { label: '7月', value: '7' },
      { label: '8月', value: '8' },
      { label: '9月', value: '9' },
      { label: '10月', value: '10' },
      { label: '11月', value: '11' },
      { label: '12月', value: '12' },
    ],
  },
  {
    label: '成本中心',
    val: '',
    field: 'costCenter',
    type: 'treeSelect',
    width: baseWidth,
    require: true,
    checkStrictly: true,
    chooseList: deptList,
  },
  {
    label: '保管部门',
    val: '',
    field: 'custodianDepartment',
    type: 'treeSelect',
    width: baseWidth,
    require: true,
    checkStrictly: true,
    chooseList: deptList,
  },
  {
    label: '保管人',
    val: '',
    field: 'custodian',
    type: 'select',
    width: baseWidth,
    remote: true,
    filterable: true,
    require: true,
    chooseList: [],
    remoteMethod: (e) => {},
    chooseListField: ['name', 'id'],
  },
  {
    label: '存放厂区',
    val: '',
    field: 'fromLocation',
    type: 'select',
    width: baseWidth,
    require: true,

    chooseList: userStore.workshopList,
    // chooseListField: ['name', 'id'],
  },
  {
    label: '存放地点',
    val: '',
    field: 'storageLocation',
    type: 'input',
    width: baseWidth,
    require: true,
  },
  {
    label: '使用性质',
    val: '',
    field: 'usageNature',
    type: 'select',
    width: baseWidth,
    require: true,

    chooseList: [
      { label: '非生产用', value: '1' },
      { label: '生产用', value: '2' },
    ],
  },
  {
    label: '资产状态',
    val: '',
    field: 'assetStatus',
    type: 'select',
    width: baseWidth,
    require: true,

    chooseList: [
      { label: '在用', value: '1' },
      { label: '非在用', value: '2' },
    ],
  },

  {
    label: '重量（吨）',
    val: '',
    field: 'weight',
    type: 'input',
    isNumber: true,
    width: baseWidth,
  },
  {
    label: '附属电机台数',
    val: '',
    field: 'affiliate_motor_count',
    type: 'input',
    isNumber: true,
    width: baseWidth,
  },
  {
    label: '附属电机总功率',
    val: '',
    field: 'totalMotorPower',
    type: 'input',
    isNumber: true,
    width: baseWidth,
  },
  {
    label: '备注',
    val: '',
    field: 'remarks',
    type: 'input',
    inputType: 'textarea',
    width: '100%',
    rightMargin: false,
    maxlength: 1000,
  },
];
